package com.swipemaster.common;

import android.util.SparseArray;

import com.google.ads.Ad;
import com.google.ads.AdListener;
import com.google.ads.AdRequest.ErrorCode;
import com.google.analytics.tracking.android.EasyTracker;

public class AdMobListener implements AdListener
{
	public final SparseArray<String> hashToNameMap = new SparseArray<String>();

	/** Full screen ad shown on exit. */
	public static final String AD_1 = "fullscreen_exit";
	/** Full screen ad shown between games. */
	public static final String AD_2 = "fullscreen_games";
	/** Banner in menu. */
	public static final String AD_3 = "banner_menu";
	/** Banner in play levels. */
	public static final String AD_4 = "banner_levels";

	@Override
	public void onDismissScreen(Ad ad)
	{
	}

	@Override
	public void onFailedToReceiveAd(Ad ad, ErrorCode error)
	{
	}

	/** User clicked on the ad, so our application will be left. */
	@Override
	public void onLeaveApplication(Ad ad)
	{
	}

	/** Called when an Activity is created in front of your app, presenting the user with a full-screen ad UI in response
	 * to their touching ad. */
	@Override
	public void onPresentScreen(Ad ad)
	{
		EasyTracker.getTracker().sendEvent(Track.ADS_CATEGORY, Track.ADS_ACTION_CLICK, getAdName(ad.hashCode()), null);
	}

	/** Called when AdView.loadAd() has succeeded. */
	@Override
	public void onReceiveAd(Ad ad)
	{
		EasyTracker.getTracker().sendEvent(Track.ADS_CATEGORY, Track.ADS_ACTION_SHOW, getAdName(ad.hashCode()), null);
	}

	private String getAdName(int hashCode)
	{
		return hashToNameMap.get(hashCode);
	}

}
